package com.leoman.plz_p.views.mine;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.leoman.plz_p.R;
import com.leoman.plz_p.adapter.ExamRecordAdapter;
import com.leoman.plz_p.interfaces.ExamRecordView;
import com.leoman.plz_p.module.bean.ExamRecordBean;
import com.leoman.plz_p.module.bean.MapData;
import com.leoman.plz_p.presenter.ExamRecordPresenter;
import com.leoman.plz_p.weidget.NavBar;

import java.util.List;

import butterknife.Bind;
import cn.com.corelib.base.BaseActivity;

/**
 * 考试记录
 */
public class ExamRecordActivity extends BaseActivity<ExamRecordView, ExamRecordPresenter> implements ExamRecordView {


    @Bind(R.id.ll_record)
    LinearLayout llRecord;

    public static Intent getLaunchIntent(Context context) {
        Intent intent = new Intent(context, ExamRecordActivity.class);
        return intent;
    }

    @Bind(R.id.nav)
    NavBar nav;
    @Bind(R.id.tv_all_count)
    TextView tvAllCount;
    @Bind(R.id.rl_circle)
    RelativeLayout rlCircle;
    @Bind(R.id.tv_pass_count)
    TextView tvPassCount;
    @Bind(R.id.tv_exam_count)
    TextView tvExamCount;
    @Bind(R.id.iv_no_record)
    ImageView ivNoRecord;
    @Bind(R.id.rl_no_record)
    RelativeLayout rlNoRecord;
    @Bind(R.id.tv_top_grade)
    TextView tvTopGrade;
    @Bind(R.id.ls_record)
    ListView lsRecord;

    private ExamRecordAdapter adapter;

    @Override
    protected int getLayoutId() {
        return R.layout.ac_exam_record;
    }

    @Override
    protected void init(Bundle savedInstanceState) {
        nav.setTitle("考试记录");
        adapter = new ExamRecordAdapter(getViewContext());
        lsRecord.setAdapter(adapter);
        lsRecord.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
//                getPresenter().getExamIds(adapter.getItem(position).getExaminId()+"");
            }
        });
    }

    @Override
    protected ExamRecordPresenter createPresenter() {
        return new ExamRecordPresenter();
    }


    @Override
    public void obtainExamRecord(MapData<ExamRecordBean> data) {
        if (data.list == null || data.list.size() == 0) {
            rlNoRecord.setVisibility(View.VISIBLE);
            llRecord.setVisibility(View.GONE);
        }else {
            adapter.replaceAll(data.list);
            tvAllCount.setText(data.total+"");
            tvPassCount.setText(data.passTotal+"");
            tvExamCount.setText(data.examinTotal+"");
            int bestSource=0;
            for (int i = 0; i <data.list.size() ; i++) {
                if (bestSource<data.list.get(i).getSource()){
                    bestSource=data.list.get(i).getSource();
                }
            }
            tvTopGrade.setText("您的历史最高成绩"+bestSource+"分");

        }
    }

    @Override
    public void obtainIds(List<String> ids,MapData data) {
//        startActivity(AnswerActivity.getLaunchIntent(getViewContext(),data.examin.getTitle(),ids.toString().replace("[","").replace("]",""),data.examin.getId()+"",data.examin.getExaminTime(),true,false));
    }


}